package com.yundingai.controller;

import com.yundingai.domain.dto.RoomInfoDTO;
import com.yundingai.domain.vo.RoomSdpVo;
import com.yundingai.service.RoomService;
import com.yundingai.vm.ResponseResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author zhaoj
 * @Date 2025/7/18 16:14
 * @Description 接收并处理前端进入自习室请求
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("room")
public class RoomController {
    @Autowired
    private RoomService roomService;
    /**
     * @Author zhaoj
     * @Date 2025/7/16 16:52
     * @Description 处理房间初始化请求
     * @Params 收到的msg，包含用户id和房间id
     **/
    @PostMapping("init")
    public ResponseResult handleMessage(@RequestBody RoomSdpVo message) {
        String type = message.getType();
        if (type.equals("init")) {
            log.info("用户{}进入房间{}", message.getFromUserId(), message.getRoomId());
        }
        return ResponseResult.okResult();
    }

    /**
     * @Author zhaoj
     * @Date 2025/7/24 16:27
     * @Description 查询房间列表
     * @Params 含筛选条件的roomconfig对象
     * @Return List<StudyRoom>
     **/
    @GetMapping("get")
    public ResponseResult getRoomList() {
        return ResponseResult.okResult(roomService.getRoomList());
    }

    /**
     * @Author zhaoj
     * @Date 2025/7/24 17:41
     * @Description 创建自习室
     * @Params [StudyRoom]
     * @Return StudyRoom
     **/
    @PostMapping("create")
    public ResponseResult createRoom(@RequestBody RoomInfoDTO room) {
        log.info("收到创建房间请求：{}",room);
        roomService.createRoom(room);
        return ResponseResult.okResult();
    }

    /**
     * @Author zhaoj
     * @Date 2025/7/28 20:29
     * @Description 房间密码验证
     * @Params [room]
     * @Return com.yundingai.vm.ResponseResult
     **/
    @PostMapping("handleInvite")
    public ResponseResult handleInvite(@RequestBody RoomInfoDTO room){
        return ResponseResult.okResult(roomService.varifyPwd(room.getRoomId(),room.getPassword()));
    }

}
